The attached patch allows external devices to migrate. The patch
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Fri, 21 Apr 2006 10:54:12 +0000 (11:54 +0100)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Fri, 21 Apr 2006 10:54:12 +0000 (11:54 +0100)
contains code that allows to at least detect local migration of a
virtual machine and handles this for the virtual TPM (results in a no-op
for local migr.). If migration of a virtual machine with attached vTPM
to another machine is attempted, XenD will return an error.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
tools/examples/Makefile
tools/examples/external-device-migrate [new file with mode: 0644]
tools/examples/vtpm-common.sh
tools/examples/vtpm-migration.sh [new file with mode: 0644]

index 93a8242637557f630c23a8af81175b038e9214ab..4cbb15658bcbe43029825cc40f69c21159b9acb4 100644 (file)
@@ -28,9 +28,11 @@ XEN_SCRIPTS += block
 XEN_SCRIPTS += block-enbd block-nbd
 XEN_SCRIPTS += vtpm vtpm-delete
 XEN_SCRIPTS += xen-hotplug-cleanup
+XEN_SCRIPTS += external-device-migrate
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
 XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
 XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh vtpm-hotplug-common.sh
+XEN_SCRIPT_DATA += vtpm-migration.sh
 
 XEN_HOTPLUG_DIR = /etc/hotplug
 XEN_HOTPLUG_SCRIPTS = xen-backend.agent
diff --git a/tools/examples/external-device-migrate b/tools/examples/external-device-migrate
new file mode 100644 (file)
index 0000000..0fb2336
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/sh
+
+# Copyright (c) 2005 IBM Corporation
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+
+# This script is called by XenD for migration of external devices
+# It does not handle the migration of those devices itself, but
+# passes the requests on to further applications
+# It handles the low-level command line parsing and some of the
+# synchronization
+
+dir=$(dirname "$0")
+. "$dir/logging.sh"
+
+
+function usage() {
+       echo " Pass the following command line paremeters to the script:"
+       echo ""
+       echo "-step <n>     : n-th migration step"
+       echo "-host <host>  : the destination host"
+       echo "-domname <domain name> : name of the domain that is migrating"
+       echo "-type <device type>    : the type of device that is migrating"
+       echo "-recover               : indicates recovery request; an error"
+       echo "                         occurred during migration"
+       echo "-help                  : display this help screen"
+}
+
+while [ 1 ]; do
+       if [ "$1" == "-step" ]; then
+               shift
+               step=$1
+       elif [ "$1" == "-host" ]; then
+               shift
+               host=$1
+       elif [ "$1" == "-domname" ]; then
+               shift
+               domname=$1
+       elif [ "$1" == "-type" ]; then
+               shift
+               typ=$1
+       elif [ "$1" == "-recover" ]; then
+               recover=1
+       elif [ "$1" == "-help" ]; then
+               usage
+               exit
+       else
+               break
+       fi
+       shift
+done
+
+if [ "$step"    == "" -o \
+     "$host"    == "" -o \
+     "$typ"     == "" -o \
+     "$domname" == "" ]; then
+       echo "Error: Parameter(s) missing (-step/-host/-type/-domname)"
+set
+       echo ""
+       echo "$0 --help for usage."
+       exit
+fi
+
+. "$dir/$typ-migration.sh"
+
+if [ "$recover" == "1" ]; then
+       func="$typ"_recover
+       eval $func $host $domname $step
+else
+       func="$typ"_migration_step
+       eval $func $host $domname $step
+fi
index f73a08627736e285d96b699f7087b1cbf4c7f807..92044a482b84b332feb3dedcb3a500de9943ad52 100644 (file)
@@ -48,6 +48,12 @@ if [ -z "$VTPM_IMPL_DEFINED" ]; then
        function vtpm_delete() {
                true
        }
+       function vtpm_migrate() {
+               echo "Error: vTPM migration accross machines not implemented."
+       }
+       function vtpm_migrate_recover() {
+               true
+       }
 fi
 
 
@@ -300,3 +306,62 @@ function vtpm_delete_instance () {
 
        release_lock vtpmdb
 }
+
+# Determine whether the given address is local to this machine
+# Return values:
+#  "-1" : the given machine name is invalid
+#  "0"  : this is not an address of this machine
+#  "1"  : this is an address local to this machine
+function isLocalAddress() {
+       local addr=$(ping $1 -c 1 |  \
+                    gawk '{ print substr($3,2,length($3)-2); exit }')
+       if [ "$addr" == "" ]; then
+               echo "-1"
+               return
+       fi
+       local res=$(ifconfig | grep "inet addr" |  \
+                  gawk -vaddr=$addr               \
+                  '{                              \
+                     if ( addr == substr($2, 6)) {\
+                       print "1";                 \
+                     }                            \
+                  }'                              \
+                 )
+       if [ "$res" == "" ]; then
+               echo "0"
+               return
+       fi
+       echo "1"
+}
+
+# Perform a migration step. This function differentiates between migration
+# to the local host or to a remote machine.
+# Parameters:
+# 1st: destination host to migrate to
+# 2nd: name of the domain to migrate
+# 3rd: the migration step to perform
+function vtpm_migration_step() {
+       local instance=$(vtpmdb_find_instance $2)
+       if [ "$instance" == "" ]; then
+               echo "Error: Translation of domain name ($2) to instance failed. Check /etc/xen/vtpm.db"
+               log err "Error during translation of domain name"
+       else
+               res=$(isLocalAddress $1)
+               if [ "$res" == "0" ]; then
+                       vtpm_migrate $1 $2 $3
+               fi
+       fi
+}
+
+# Recover from migration due to an error. This function differentiates
+# between migration to the local host or to a remote machine.
+# Parameters:
+# 1st: destination host the migration was going to
+# 2nd: name of the domain that was to be migrated
+# 3rd: the last successful migration step that was done
+function vtpm_recover() {
+       res=$(isLocalAddress $1)
+       if [ "$res" == "0" ]; then
+               vtpm_migrate_recover $1 $2 $3
+       fi
+}
diff --git a/tools/examples/vtpm-migration.sh b/tools/examples/vtpm-migration.sh
new file mode 100644 (file)
index 0000000..7e38ae2
--- /dev/null
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2005 IBM Corporation
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+dir=$(dirname "$0")
+. "$dir/vtpm-common.sh"